# 论文R/G比率与浓度的映射关系（图6）
from os import close

ratio_conc_dict = {     #先建立已知数据字典：一一对应
    2.31: 0,    # 0 μmol/L
    1.85: 5,    # 5 μmol/L
    1.40: 10,   # 10 μmol/L
    0.95: 15,   # 15 μmol/L
    0.50: 20,   # 20 μmol/L
    0.25: 25,   # 25 μmol/L
    0.10: 30    # 30 μmol/L
}
def predict_concentration(measured_R,measured_G):
    measured_ratio = measured_R/measured_G
    closest_ratio = min(ratio_conc_dict.keys(),key=lambda A:abs(A-measured_ratio))
    #在字典里找出最接近实测数据的值返回
    return ratio_conc_dict[closest_ratio]
    #调用函数检测
predict_conc = predict_concentration(1.20,1.03)
print(f"当R=1.20,G=1.03:预测汞离子浓度：{predict_conc}")